package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbMaterialParam;
import com.sailfish.springbootdemo.pojo.db2.PcbNewTechnologyInfo;
import com.sailfish.springbootdemo.pojo.db2.PcbNewTechnologyPic;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * (TbPcbNewTechnologyPic)表数据库访问层
 *
 * @author makejava
 * @since 2023-08-16 11:16:15
 */
public interface PcbNewTechnologyPicDao {

    @Results(id = "pcbNewTechnologyPicResultMap", value = {
            @Result(column = "pcb_pic_id", property = "pcbPicId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcb_new_technology_info_id", property = "pcbNewTechnologyInfoId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pic_name", property = "picName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pic_extend", property = "picExtend", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pic_relate_path", property = "picRelatePath", jdbcType = JdbcType.VARCHAR),
            @Result(column = "url", property = "url", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })

    /*
     * 单个查询
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC +
            " where 1 = 1 " +
            "<if test='id != null'>" +
            " and pcb_pic_id = #{id}" +
            "</if>" +
            " order by sort" +
            "</script>")
    List<PcbNewTechnologyPic> getAllById(@Param("id") Integer id);

    /*
     * 查询指定行数据
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC +
            " where 1 = 1 " +
            "<if test='pcbNewTechnologyInfoId != null'>" +
            " and pcb_new_technology_info_id = #{pcbNewTechnologyInfoId}" +
            "</if>" +
            "<if test='picName != null'>" +
            " and pic_name = #{picName}" +
            "</if>" +
            "<if test='picExtend != null'>" +
            " and pic_extend = #{picExtend}" +
            "</if>" +
            "<if test='picRelatePath != null'>" +
            " and pic_relate_path = #{picRelatePath}" +
            "</if>" +
            "<if test='remark != null'>" +
            " and remark = #{remark}" +
            "</if>" +
            "<if test='createUser != null'>" +
            " and create_user = #{createUser}" +
            "</if>" +
            " order by sort" +
            "</script>")
    @ResultMap(value = "pcbNewTechnologyPicResultMap")
    List<PcbNewTechnologyPic> getAllByLimit(PcbNewTechnologyPic param);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC + " (pcb_new_technology_info_id, pic_name, pic_extend, pic_relate_path, url, remark, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{pcbNewTechnologyInfoId}, #{picName}, #{picExtend}, #{picRelatePath}, #{url}, #{remark}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    // 显式设置主键
    @Options(useGeneratedKeys = true, keyProperty = "pcbPicId")
    Integer insert(PcbNewTechnologyPic param);

    /*
     *批量新增
     */
    @Insert("<script>" +
            "insert into " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC + " (pcb_new_technology_info_id, pic_name, pic_extend, pic_relate_path, url, remark, create_time, create_user, update_time, update_user, status, sort) values " +
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(#{entity.pcbNewTechnologyInfoId}, #{entity.picName}, #{entity.picExtend}, #{entity.picRelatePath}, #{entity.url}, #{entity.remark}, #{entity.createTime}, #{entity.createUser}, #{entity.updateTime}, #{entity.updateUser}, #{entity.status}, #{entity.sort})" +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "pcbPicId")
    Integer insertBatch(@Param("entities") List<PcbNewTechnologyPic> entities);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC + " where pcb_pic_id = #{id} ")
    Integer delete(@Param("id") Integer id);

    /*
     *通过新技术主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC + " where pcb_new_technology_info_id = #{id} ")
    Integer deleteByInfoId(@Param("id") Integer id);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_NEW_TECHNOLOGY_PIC +
            "<set> " +
            "<if test='pcbNewTechnologyInfoId != null'>" +
            "pcb_new_technology_info_id = #{pcbNewTechnologyInfoId}," +
            "</if>" +
            "<if test='picName != null'>" +
            "pic_name = #{picName}," +
            "</if>" +
            "<if test='picExtend != null'>" +
            "pic_extend = #{picExtend}," +
            "</if>" +
            "<if test='picRelatePath != null'>" +
            "pic_relate_path = #{picRelatePath}," +
            "</if>" +
            "<if test='remark != null and remark != \"\"'>" +
            "remark = #{remark}," +
            "</if>" +
            "<if test='url != null and url != \"\"'>" +
            "url = #{url}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "create_user = #{createUser}," +
            "</if>" +
            "<if test='createTime != null '>" +
            "create_time = #{createTime}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "update_user =#{updateUser}," +
            "</if>" +
            "<if test='updateTime != null '>" +
            "update_time = #{updateTime}," +
            "</if>" +
            "<if test='status != null '>" +
            "status = #{status}," +
            "</if>" +
            "<if test='sort != null '>" +
            "sort = #{sort} " +
            "</if>" +
            "</set> " +
            "where pcb_pic_id = #{pcbPicId}" +
            "</script>")
    Integer update(PcbNewTechnologyPic param);
}

